namespace SinaFinance.SummaryInfoLibrary
{
    using SinaFinance;
    using SinaFinanceBaseClassLibrary;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;

    public partial class StockProfessionInformationArea : UserControl
    {
        //private bool _contentLoaded;
        private LinearGradientBrush brush = new LinearGradientBrush();
        private DB_SinaDataHelp Dsdh;
        //internal Grid LayoutRoot;
        private loading loadBar;
        //internal Canvas rootCanvas;

        public StockProfessionInformationArea()
        {
            this.InitializeComponent();
            this.brush.StartPoint = new Point(0.5, 0.0);
            this.brush.EndPoint = new Point(0.5, 1.0);
            GradientStop stop = new GradientStop();
            GradientStop stop2 = new GradientStop();
            stop.Color = Color.FromArgb(0xff, 0xec, 0xff, 0xff);
            stop2.Color = Color.FromArgb(0xff, 0xae, 0xbf, 0xc7);
            stop2.Offset = 1.0;
            this.brush.GradientStops.Add(stop);
            this.brush.GradientStops.Add(stop2);
            this.AddLoadingToCanvas();
        }

        private void AddLoadingToCanvas()
        {
            this.loadBar = new loading();
            this.loadBar.Margin = new Thickness((this.LayoutRoot.Width / 2.0) - (this.loadBar.Width / 2.0), (this.LayoutRoot.Height / 2.0) - (this.loadBar.Height / 2.0), 0.0, 0.0);
            this.rootCanvas.Children.Add(this.loadBar);
        }

        private void Dsdh_GetNewsInfoCompleted(List<DB_News> _DB_News)
        {
            this.rootCanvas.Children.Clear();
            if (_DB_News != null)
            {
                for (int i = 0; i < _DB_News.Count; i++)
                {
                    StockProfessionInformationItem item = new StockProfessionInformationItem {
                        Margin = new Thickness(0.0, (23.0 * i) - 1.0, 0.0, 0.0),
                        ItemContent = _DB_News[i].Title,
                        NewsDate = _DB_News[i].Date,
                        NewsID = _DB_News[i].NewsID,
                        NewsHref = _DB_News[i].NewsHref,
                        NewsSymbol = _DB_News[i].Symbol,
                        Foreground = this.brush
                    };
                    this.rootCanvas.Children.Add(item);
                }
            }
        }

        public void GenerateNewsInfo(string symbol)
        {
            if (!string.IsNullOrEmpty(symbol))
            {
                this.rootCanvas.Children.Clear();
                this.AddLoadingToCanvas();
                if (this.Dsdh == null)
                {
                    this.Dsdh = new DB_SinaDataHelp();
                    this.Dsdh.GetNewsInfoCompleted += new GetNewsInfoDataHelp(this.Dsdh_GetNewsInfoCompleted);
                }
                this.Dsdh.GetNewsInfoData(symbol);
            }
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/SummaryInfoLibrary/StockProfessionInformationArea.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}
    }
}
